﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Npgsql;

namespace frmPrincipal
{
    public partial class frmConsultaBasica : Form
    {
        StandardDBConnection standardDBConnection = new StandardDBConnection();
        string sqlCommandText;

        //
        private void reSize()
        {
            grdConsulta.Size = new Size(this.Size.Width - 40, this.Size.Height - 60);
        }

        public frmConsultaBasica(string title, string sqlCommandText, int grdX, int grdY)
        {            
            Size grdSize = new Size(grdX, grdY);
            Size frmSize = new Size(grdX + 40, grdY+60);
            InitializeComponent();

            this.sqlCommandText = sqlCommandText;
            this.Text = title;
            this.Size = frmSize;
            grdConsulta.Size = grdSize;
            
        }

        private void frmConsultaBasica_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            NpgsqlDataAdapter da;

            da = new NpgsqlDataAdapter(sqlCommandText, standardDBConnection.cnn);

            ds.Reset();
            da.Fill(ds);
            dt = ds.Tables[0];
            grdConsulta.DataSource = dt;
            standardDBConnection.cnn.Close();

        }

        private void frmConsultaBasica_Resize(object sender, EventArgs e)
        {
            reSize();
        }

    }
}
